<?php

namespace app\admin\model\secgoods;

use app\admin\model\users\Users;
use think\Model;


class SecGoods extends Model
{

    

    

    // 表名
    protected $name = 'sec_goods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text',
        'is_sale_text'
    ];
    

    
    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1')];
    }

    public function getIsSaleList()
    {
        return ['0' => __('Is_sale 0'), '1' => __('Is_sale 1')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsSaleTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_sale']) ? $data['is_sale'] : '');
        $list = $this->getIsSaleList();
        return isset($list[$value]) ? $list[$value] : '';
    }
	
	function users()
	{
		return $this->belongsTo(Users::class,'users_id');
	}
	
	function class()
	{
		return $this->belongsTo(SecGoodsClass::class,'class_id');
	}



}
